<style>
.fui-tab.fui-tab-danger a.active {
    color: #333;
    border-color: #333;
	font-weight:400;
	border-bottom: 1px solid #333;
}
</style>
<div class="fui-page fui-page-current page-goods-list" ng-if="pagedata.op=='main'">
    <div class="fui-content navbar" style="top:0">
		<div id="tab" class="fui-tab fui-tab-danger" style="padding:0 1rem">
			<a style="width:4rem" ng-class="{'external active' : pagedata.params.cid == 0}" href="javascript:" ng-click="pagedata.get_list(1,0);">全部</a>
			<a style="width:4rem" ng-repeat="c in pagedata.category" ng-class="{'external active' : pagedata.params.cid == c.id}" href="javascript:" ng-click="pagedata.get_list(1,c.id);">当前房屋</a>
		</div>
	    <div class='content-empty' ng-if="pagedata.list.length<1">
			<i class='icon icon-search'></i><br/>暂时没有任何商品
	    </div>
		<div class="fui-cell-group">
			<div class="fui-cell" ng-repeat="g in pagedata.list" ng-click="access_json(g.active.url || 'jy_weishop/goods.detail//id='+g.id)">
					<div class="fui-cell-label" style="width:4rem"><img style="width:3rem;height:3rem" ng-src="{{tomedia(g.image) || '../core/resource/images/nopic.jpg'}}"  /></div>
					<div class="fui-cell-text">
						<div class="text bold">{{g.title}}</div>
						<div style="margin:0.5rem 0"><span class="price red" style="line-height:1rem">￥{{g.active.price || g.price}}</span><span class="fui-tag-red" style="margin-left:0.5rem;border-radius: 0.1rem;padding:0.1rem 0.3rem">便利</span><span class="fui-tag-red-big r-f" style="font-size:0.6rem">立即购买</span></div>
					</div>
			</div>
		</div>
	    <div id="loading" class='infinite-loading'><span class='fui-preloader'></span><span class='text'> 正在加载...</span></div>
	</div>
</div>
<script>
scope.pagedata.showfilter=function(){
		$('#showfilter').modal();
}
scope.pagedata.params.order='default'
scope.pagedata.list=[];
scope.pagedata.get_list=function(first,cid){
	scope.pagedata.params.cid=cid;
	if(first){
				//初次加载
				scope.pagedata.page=1;
				scope.pagedata.list=[];
				scope.pagedata.loaded=false;
				$('#loaded').hide();
	}else if(!scope.pagedata.page){
				scope.pagedata.page=1;
	}else{
				scope.pagedata.page++;
	}
	if(scope.pagedata.loaded){
				return;
	}
	if(scope.pagedata.loading){
				return;
	}else{
				scope.pagedata.loading=true;
	}
	$('#loading').show();$('#loadmore').hide();
	var query='page='+scope.pagedata.page;
	if(scope.page.query){
		query+='&'+scope.page.query;
	}
	var more_query=scope.made_query(scope.pagedata.params);
	if(more_query){
		query+='&'+more_query;
	}
	scope.get_data(function(res){
		if(!Array.isArray(res.list)){
						console.log('数据加载失败！');
						console.log(res);
						return;
		}
		if(res.list.length==0){
				scope.pagedata.loaded=true;
					scope.$evalAsync();
					scope.pagedata.loading=false;
					$('#loading').hide();
					$('#loaded').show();
					if(scope.pagedata.list.length==0){
						$('#no_goods').show();
					}
					return;
		}
		res.list.forEach(function(v){
					scope.pagedata.list.push(v);
		});
		if(res.list.length<1){
				scope.isnodata=true;
		}
		scope.pagedata.loading=false;
		scope.$evalAsync();
		$('#loading').hide();
		$('#loadmore').show();
				
	},'',{'op':'getlist','query':query});
}
//首次加载
scope.pagedata.get_list(true,0);
//滑到页面底部时加载下一页
window.addEventListener('scroll', function () {
	//alert('准备加载第二页');console.log('scope.isnodata');console.log(scope.loading);
	 var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
	// console.log(scrollTop);
    if(!scope.isnodata && !scope.pagedata.loading &&  (scrollTop + window.innerHeight) >= document.documentElement.scrollHeight){
        scope.loading = true;  //状态标记
		scope.pagedata.get_list();
     }
})
	</script>